import VueRouter from "vue-router";
import Vue from "vue";

Vue.use(VueRouter);

const routes = [{
        path: '/',
        redirect: '/welcome'
    },{
        path: '/welcome',
        name: 'Welcome',
        meta: { show: true },
        component: () => import('@/views/welcome'),
    },{
        path: '/home',
        name: 'Home',
        component: () => import('@/views/home'),
    },{
        path: '/book',
        name: 'Book',
        component: () => import('@/views/book'),
    }
    ,{
        path: '/shoppingCart',
        name: 'ShoppingCart',
        component: () => import('@/views/shoppingCart'),
    }
]


const router = new VueRouter({
    routes,
})
//路由守卫
// router.beforeEach(function(to, from, next){
//     const token = localStorage.getItem('username');

//   // 如果用户尝试访问的路由需要认证且用户未登录，则重定向到登录页
//   if ((to.path==='/home' || to.path==='/book' || to.path==='/shoppingCart') && !token) {
//     next('/welcome');
//   } else {
//     next();
//   }
//   });
export default router